package com.kehutong.payment.util;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.coraframework.json.JSONObject;
import org.coraframework.util.Objects;

/**
 * 此类处理下拉框数据
 * 由于下拉框可以选择多个选项
 * @author qiaojunying
 * @date 2020-05-05
 *
 */
public class DataUtil {
	
	
    /**
     * 微信返回信息
     * 
     * @throws IOException
     */
    public String getMessage(TencentPayResult result) throws IOException {
    	return getMessage(result, null);
    }
    
    /**
     * 微信返回信息
     * 
     * @throws IOException
     */
    public String getMessage(TencentPayResult result, String msg) {
    	StringBuilder buffer = new StringBuilder();
    	
    	buffer.append("<xml>");
    	buffer.append("<return_code><![CDATA[").append(result).append("]]></return_code>");
    	if (Objects.nonEmpty(msg)){
            buffer.append("<return_msg><![CDATA[").append(msg).append("]]></return_msg>");
        }
    	buffer.append("</xml>");
    	
    	return buffer.toString();
    }
    
    /**
     * 获取拼接后的新项目编号
     * @param termNo
     * @return
     */
    public static String getTermNo(String termNo){
        StringBuilder sb = new StringBuilder("('");
        if(termNo == null || "".equals(termNo)){
            return "";
        }
        if(termNo.indexOf(",") == -1){
            return sb.append(termNo+"')").toString();
        }else{
            String[] termNos = termNo.split(",");
            for(String str : termNos){
                sb.append(str+"',");
            }
        }
        return sb.toString().substring(0,sb.toString().length()-1)+")";
    }

    /**
     * 获取拼接后的新群编号
     * @param roomNo
     * @return
     */
    public static String getRoomNo(String roomNo){
        StringBuilder sb = new StringBuilder("('");
        if(roomNo == null || "".equals(roomNo)){
            return "";
        }
        if(roomNo.indexOf(",") == -1){
            return sb.append(roomNo+"')").toString();
        }else{
            String[] roomNos = roomNo.split(",");
            for(String str : roomNos){
                sb.append(str+"',");
            }
        }
        return sb.toString().substring(0,sb.toString().length()-1)+")";
    }

    public static Map<String,Object> getDataMap(JSONObject jsonObject){
        Map<String,Object> map = new HashMap<>();
        String termNo = jsonObject.getString("termNo");
        String chatRoomNo = jsonObject.getString("chatRoomNo");
        String startDate = jsonObject.getString("startDate");
        String endDate = jsonObject.getString("endDate");
        map.put("termNo",termNo);
        map.put("chatRoomNo",chatRoomNo);
        map.put("startDate",startDate);
        map.put("endDate",endDate);
        return map;
    }

    public static String getDaysOfWeek(String day,int value){
        String days = "";
        if(Objects.isEmpty(day)){
            return null;
        }
        switch (day){
            case "0":
                days = "星期日";
                break;
            case "1":
                days = "星期一";
                break;
            case "2":
                days = "星期二";
                break;
            case "3":
                days = "星期三";
                break;
            case "4":
                days = "星期四";
                break;
            case "5":
                days = "星期五";
                break;
            case "6":
                days = "星期六";
                break;
        }
        return days;
    }

    public static String convertDays(String day){
        String days = "";
        if(Objects.isEmpty(day)){
            return "";
        }
        switch (day){
            case "0":
                days = "星期日";
                break;
            case "1":
                days = "星期一";
                break;
            case "2":
                days = "星期二";
                break;
            case "3":
                days = "星期三";
                break;
            case "4":
                days = "星期四";
                break;
            case "5":
                days = "星期五";
                break;
            case "6":
                days = "星期六";
                break;
        }
        return days;
    }

    public static String[] getData(){
        String[] data = {"0","1","2","3","4","5","6"};
        return data;
    }

    public static String[] getHours(){
        String[] data = {"0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23"};
        return data;
    }
}
